import moment from 'moment'

const isBorwser = process.browser
export default {
  // 获取编辑区版式
  getSlideTemplates: {SQL: `select * from yx_ct_bs`},
  // 获取编辑区风格
  getSlideStyles: {SQL: `select * from yx_ct_fg order by styleName`},
  // 获取封面
  getSlideCover: {SQL: `select * from yx_ct_fm`},
  // 获取字体样式
  getSlideFonts: {SQL: `select * from yx_ct_zt`},
  // 获取播放动画
  getSlideAnimatios: {SQL: `select * from yx_ct_dh`},
  // 获取预置文件
  getDefaultFiles: {SQL: `select b.WJID,b.ID,b.IMG,b.[ORDER] from yx_fj_wj a inner join yx_fj_tpl b on a.id=b.wjid where a.scsj is null`},
  // 获取编辑区元素
  getSlideElements (parameter) {
    return {SQL: `select * from yx_ct_ys where sid in(${parameter}) order by sid ,[index]`}
  },
  // 获取编辑区元素样式
  getSlideEleStyle (parameter) {
    return {SQL: `select * from yx_ct_ysys where sid in(${parameter})`}
  },
  // 获取编辑区元素动画
  getSlideEleAnimation (parameter) {
    return {SQL: `select a.sid,a.eid,b.id,b.value name,time from yx_ct_ysdh a inner join yx_ct_dh b on a.aid = b.id where sid in(${parameter})`}
  },
  // 获取编辑区图片缩放对象
  getSlideZoomEle (parameter) {
    return {SQL: `select sid,eid,zoomScale,top,[left] from yx_ct_yssf where sid in(${parameter})`}
  },
  // 添加风格
  addSlideStyle: (arg) => {
    if (isBorwser) {
      return {
        SQL: `insert into yx_ct_fg(id,styleName)values(?,?)`,
        parameter: {1: arg.id, 2: arg.styleName}
      }
    } else {
      return {
        SQL: `insert into yx_ct_fg(id,styleName)values($id,$styleName)`,
        Parameter: {'$id': arg.id, '$styleName': arg.styleName}
      }
    }
  },
  // 添加版式
  addSlideTemplate: (arg) => {
    if (isBorwser) {
      return {
        SQL: `insert into yx_ct_bs(id,templateName) values(?,?)`,
        parameter: {1: arg.id, 2: arg.templateName}
      }
    } else {
      return {
        SQL: `insert into yx_ct_bs(id,templateName) values($id,$templateName)`,
        Parameter: {'$id': arg.id, '$templateName': arg.templateName}
      }
    }
  },
  // 添加封面
  addSlideCover: (arg) => {
    if (isBorwser) {
      return {
        SQL: `INSERT INTO yx_ct_fm (id,coverName)VALUES (?,?)`,
        parameter: {1: arg.id, 2: arg.coverName}
      }
    } else {
      return {
        SQL: `INSERT INTO yx_ct_fm (id,coverName)VALUES ($id,$coverName)`,
        Parameter: {'$id': arg.id, '$coverName': arg.coverName}
      }
    }
  },
  // 修改封面文本
  setSlideCoverText: (param) => {
    if (isBorwser) {
      return [{
        SQL: `update yx_ct_fm set coverText=? where id=?`,
        parameter: {1: param.coverText, 2: param.id}
      }]
    } else {
      return [{
        SQL: `update yx_ct_fm set coverText=$coverText where id=$id`,
        Parameter: {'$coverText': param.coverText, '$id': param.id}
      }]
    }
  },
  // 添加元素
  addSlideElement: (arg) => {
    if (isBorwser) {
      return {
        SQL: `INSERT INTO yx_ct_ys (sid,id,name,type,text,html,path,[index],width,height,[left],top,isEdit,lockHeight,lockWidth,lockMove,lockSelect,templateElement,show,fileCode) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
        parameter: {
          1: arg.sid,
          2: arg.id,
          3: arg.name,
          4: arg.type,
          5: arg.text,
          6: arg.html,
          7: arg.path,
          8: arg.index,
          9: arg.width,
          10: arg.height,
          11: arg.left,
          12: arg.top,
          13: arg.isEdit,
          14: arg.lockHeight,
          15: arg.lockWidth,
          16: arg.lockMove,
          17: arg.lockSelect,
          18: arg.templateElement,
          19: arg.show,
          20: arg.fileCode
        }
      }
    } else {
      return {
        SQL: `INSERT INTO yx_ct_ys (sid,id,name,type,text,html,path,[index],width,height,[left],top,isEdit,lockHeight,lockWidth,lockMove,lockSelect,templateElement,show,fileCode) VALUES ($sid,$id,$name,$type,$text,$html,$path,$index,$width,$height,$left,$top,$isEdit,$lockHeight,$lockWidth,$lockMove,$lockSelect,$templateElement,$show,$fileCode)`,
        Parameter: {
          '$sid': arg.sid,
          '$id': arg.id,
          '$name': arg.name,
          '$type': arg.type,
          '$text': arg.text,
          '$html': arg.html,
          '$path': arg.path,
          '$index': arg.index,
          '$width': arg.width,
          '$height': arg.height,
          '$left': arg.left,
          '$top': arg.top,
          '$isEdit': arg.isEdit,
          '$lockHeight': arg.lockHeight,
          '$lockWidth': arg.lockWidth,
          '$lockMove': arg.lockMove,
          '$lockSelect': arg.lockSelect,
          '$templateElement': arg.templateElement,
          '$show': arg.show,
          '$fileCode': arg.fileCode
        }
      }
    }
  },
  addElementStyle: (arg) => {
    if (isBorwser) {
      return {
        SQL: `INSERT INTO yx_ct_ysys (sid,eid,[font-family],[font-size],color,[font-weight],[font-style],[text-decoration],[text-align],[border-width],[border-style],[border-color],[background-color])VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`,
        parameter: {
          1: arg.sid,
          2: arg.eid,
          3: arg.fontfamily,
          4: arg.fontsize,
          5: arg.color,
          6: arg.fontweight,
          7: arg.fontstyle,
          8: arg.textdecoration,
          9: arg.textalign,
          10: arg.borderwidth,
          11: arg.borderstyle,
          12: arg.bordercolor,
          13: arg.backgroundcolor
        }
      }
    } else {
      return {
        SQL: `INSERT INTO yx_ct_ysys (sid,eid,[font-family],[font-size],color,[font-weight],[font-style],[text-decoration],[text-align],[border-width],[border-style],[border-color],[background-color])VALUES ($sid,$eid,$fontfamily,$fontsize,$color,$fontweight,$fontstyle,$textdecoration,$textalign,$borderwidth,$borderstyle,$bordercolor,$backgroundcolor)`,
        Parameter: {
          '$sid': arg.sid,
          '$eid': arg.eid,
          '$fontfamily': arg.fontfamily,
          '$fontsize': arg.fontsize,
          '$color': arg.color,
          '$fontweight': arg.fontweight,
          '$fontstyle': arg.fontstyle,
          '$textdecoration': arg.textdecoration,
          '$textalign': arg.textalign,
          '$borderwidth': arg.borderwidth,
          '$borderstyle': arg.borderstyle,
          '$bordercolor': arg.bordercolor,
          '$backgroundcolor': arg.backgroundcolor
        }
      }
    }
  },
  addElementAnimation: (arg) => {
    if (isBorwser) {
      return {
        SQL: `INSERT INTO yx_ct_ysdh (sid,eid,aid,time)VALUES (?,?,?,?)`,
        parameter: {
          1: arg.sid,
          2: arg.eid,
          3: arg.aid,
          4: arg.time
        }
      }
    } else {
      return {
        SQL: `INSERT INTO yx_ct_ysdh (sid,eid,aid,time)VALUES ($sid,$eid,$aid,$time)`,
        Parameter: {
          '$sid': arg.sid,
          '$eid': arg.eid,
          '$aid': arg.aid,
          '$time': arg.time
        }
      }
    }
  },
  addElementZoom: (arg) => {
    if (isBorwser) {
      return {
        SQL: `INSERT INTO yx_ct_yssf (sid,eid,zoomScale,top,left)VALUES (?,?,?,?,?)`,
        parameter: {
          1: arg.sid,
          2: arg.eid,
          3: arg.zoomScale,
          4: arg.top,
          5: arg.left
        }
      }
    } else {
      return {
        SQL: `INSERT INTO yx_ct_yssf (sid,eid,zoomScale,top,left)VALUES ($sid,$eid,$zoomScale,$top,$left)`,
        Parameter: {
          '$sid': arg.sid,
          '$eid': arg.eid,
          '$zoomScale': arg.zoomScale,
          '$top': arg.top,
          '$left': arg.left
        }
      }
    }
  },
  // 删除元素
  delAllElements: (sid) => {
    if (isBorwser) {
      return {
        SQL: `delete from yx_ct_ys where sid=?`,
        parameter: {1: sid}
      }
    } else {
      return {
        SQL: `delete from yx_ct_ys where sid=$sid`,
        Parameter: {'$sid': sid}
      }
    }
  },
  delAllEleStyle: (sid) => {
    if (isBorwser) {
      return {
        SQL: `delete from yx_ct_ysys where sid=?`,
        parameter: {1: sid}
      }
    } else {
      return {
        SQL: `delete from yx_ct_ysys where sid=$sid`,
        Parameter: {'$sid': sid}
      }
    }
  },
  delAllEleAnimation: (sid) => {
    if (isBorwser) {
      return {
        SQL: `delete from yx_ct_ysdh where sid=?`,
        parameter: {1: sid}
      }
    } else {
      return {
        SQL: `delete from yx_ct_ysdh where sid=$sid`,
        Parameter: {'$sid': sid}
      }
    }
  },
  delAllEleZoom: (sid) => {
    if (isBorwser) {
      return {
        SQL: `delete from yx_ct_yssf where sid=?`,
        parameter: {1: sid}
      }
    } else {
      return {
        SQL: `delete from yx_ct_yssf where sid=$sid`,
        Parameter: {'$sid': sid}
      }
    }
  },
  // 删除外部文件
  delExternalFile: (param) => {
    if (isBorwser) {
      return [
        {
          SQL: `update yx_fj_wj set sfsc='Y' where id=?`,
          parameter: {1: param}
        },
        {
          SQL: `update yx_fj_tpl set sfsc='Y' where WJID=?`,
          parameter: {1: param}
        }]
    } else {
      return [
        {
          SQL: `update yx_fj_wj set sfsc='Y' where id=$ID`,
          Parameter: {$ID: param}
        },
        {
          SQL: `update yx_fj_tpl set sfsc='Y' where WJID=$WJID`,
          Parameter: {$WJID: param}
        }]
    }
  },
  // 删除外部文件流
  delExternalFileStream: (param) => {
    if (isBorwser) {
      return {
        SQL: `update yx_fj_tpl set sfsc='Y' where WJID=? and ID=?`,
        parameter: {1: param.WJID, 2: param.ID}
      }
    } else {
      return {
        SQL: `update yx_fj_tpl set sfsc='Y' where WJID=$WJID and ID=$ID`,
        Parameter: {$WJID: param.WJID, $ID: param.ID}
      }
    }
  },
  addImageStream: (param) => {
    if (isBorwser) {
      let executeSql = []
      executeSql.push({
        SQL: 'INSERT INTO yx_fj_wj (ID,WJL,SCSJ)VALUES (?,?,?)',
        parameter: {1: param.fileID, 2: param.IMG, 3: moment().format('YYYY-MM-DD hh:mm:ss')}
      })
      executeSql.push({
        SQL: 'INSERT INTO yx_fj_tpl (WJID,ID,IMG,[ORDER])VALUES (?,?,?,?)',
        parameter: {1: param.fileID, 2: param.ID, 3: param.IMG, 4: '1'}
      })
      return executeSql
    } else {
      let executeSql = []
      executeSql.push({
        SQL: 'INSERT INTO yx_fj_wj (ID,WJL,SCSJ)VALUES ($ID,$WJL,$SCSJ)',
        Parameter: {'$ID': param.fileID, '$WJL': param.IMG, '$SCSJ': moment().format('YYYY-MM-DD hh:mm:ss')}
      })
      executeSql.push({
        SQL: 'INSERT INTO yx_fj_tpl (WJID,ID,IMG,[ORDER])VALUES ($WJID,$ID,$IMG,$ORDER)',
        Parameter: {'$WJID': param.fileID, '$ID': param.ID, '$IMG': param.IMG, '$ORDER': '1'}
      })
      return executeSql
    }
  },
  eidtSlideTitle: (param) => {
    if (isBorwser) {
      return {
        executeSql: [{
          SQL: `update yx_ct_ys set text=?,html=? where sid=? and type='TEXT' and [index]=1`,
          parameter: {1: param.id, 2: param.text, 3: param.text}
        }]
      }
    } else {
      return {
        executeSql: [{
          SQL: `update yx_ct_ys set text=$TEXT,html=$HTML where sid=$SID and type='TEXT' and [index]=1`,
          Parameter: {SID: param.id, TEXT: param.text, HTML: param.text}
        }]
      }
    }
  }
}
